package com.yehongyu.mytools.ui.applet;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LabelApplet extends Applet implements ActionListener{

	/**序列ID*/
	private static final long serialVersionUID = 1L;


	TextField t1 = new TextField("t1", 10);

	Label labl1 = new Label("TextField t1");
	Label labl2 = new Label("                   ");
	Label labl3 = new Label("                    ", Label.RIGHT);

	Button b1 = new Button("Test 1");
	Button b2 = new Button("Test 2");

	public void init() {
		add(labl1);
		add(t1);
		add(b1);
		add(labl2);
		add(b2);
		add(labl3);
		b1.addActionListener(this);
		b2.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(b1)){
			labl2.setText("Text set into Label");
		}else if(e.getSource().equals(b2)){
			if (labl3.getText().trim().length() == 0)
				labl3.setText("labl3");
			if (labl3.getAlignment() == Label.LEFT)
				labl3.setAlignment(Label.CENTER);
			else if (labl3.getAlignment() == Label.CENTER)
				labl3.setAlignment(Label.RIGHT);
			else if (labl3.getAlignment() == Label.RIGHT)
				labl3.setAlignment(Label.LEFT);
		}else{
			System.out.println("Unknown Action!");
		}
	}

}
